package com.hongye.backstage.controller;

import com.github.pagehelper.PageInfo;
import com.hongye.backstage.entity.HongyeAuditEntity;
import com.hongye.backstage.entity.HongyeConsultEntity;
import com.hongye.backstage.service.HongyeAuditService;
import com.hongye.backstage.vo.AuditQueryVo;
import com.hongye.backstage.vo.ConsultVo;
import com.hongye.common.enu.ResultEnum;
import com.hongye.common.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author fyd
 * @email 2104371759@qq.com
 * @date 2022/4/20
 * @time 9:23
 */
@RestController
@RequestMapping("/backstage/audit")
public class HongyeAuditController {

    @Autowired
    private HongyeAuditService hongyeAuditService;

    /**
     * 后台 审核管理列表
     * @param pageNum 当前页
     * @param pageSize 每页总条数
     * @param vo 条件查 vo
     * @return
     */
    @RequestMapping("/getAuditList")
    public ResponseResult getAuditList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize",defaultValue = "5") Integer pageSize,
                                       @RequestBody AuditQueryVo vo){
        ResponseResult<Object> result = new ResponseResult<>();
        try {
            PageInfo<HongyeAuditEntity> pageInfo = hongyeAuditService.getAuditList(pageNum,pageSize,vo);
            result.setSuccess(ResultEnum.SUCCESS.getSuccess());
            result.setCode(ResultEnum.SUCCESS.getCode());
            result.setMessage(ResultEnum.SUCCESS.getMessage());
            result.setData(pageInfo);
            return result;
        }catch (Exception e){
            e.printStackTrace();
            result.setSuccess(ResultEnum.ERROR.getSuccess());
            result.setMessage(ResultEnum.ERROR.getMessage());
            result.setCode(ResultEnum.ERROR.getCode());
            return result;
        }

    }

    /**
     * 审核 修改状态
     * @param id 编号
     * @param status 状态
     * @return
     */
    @RequestMapping("/updateStatusById")
    public ResponseResult updateStatusById(@RequestParam("id") Integer id,@RequestParam("status") Integer status){
        int i = hongyeAuditService.updateStatusById(id,status);
        ResponseResult<Integer> result = new ResponseResult<>();
        if (i > 0){
            result.setSuccess(ResultEnum.SUCCESS.getSuccess());
            result.setMessage(ResultEnum.SUCCESS.getMessage());
            result.setCode(ResultEnum.SUCCESS.getCode());
            result.setData(i);
            return result;
        }
        result.setSuccess(ResultEnum.ERROR.getSuccess());
        result.setCode(ResultEnum.ERROR.getCode());
        result.setMessage(ResultEnum.ERROR.getMessage());
        return result;
    }

    /**
     * 后台 咨询管理列表
     * @param pageNum 当前页
     * @param pageSize 每页总条数
     * @param vo 条件查 vo
     * @return
     */
    @RequestMapping("/getConsultationList")
    public ResponseResult getConsultationList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pageSize",defaultValue = "3") Integer pageSize,
                                       @RequestBody ConsultVo vo){
        ResponseResult<Object> result = new ResponseResult<>();
        try {
            PageInfo<HongyeConsultEntity> pageInfo = hongyeAuditService.getConsultationList(pageNum,pageSize,vo);
            result.setSuccess(ResultEnum.SUCCESS.getSuccess());
            result.setCode(ResultEnum.SUCCESS.getCode());
            result.setMessage(ResultEnum.SUCCESS.getMessage());
            result.setData(pageInfo);
            return result;
        }catch (Exception e){
            e.printStackTrace();
            result.setSuccess(ResultEnum.ERROR.getSuccess());
            result.setMessage(ResultEnum.ERROR.getMessage());
            result.setCode(ResultEnum.ERROR.getCode());
            return result;
        }

    }

}
